<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>共享工作者 - Page 2</title>
</head>
<body>
    <h1>共享工作者线程 - Page 2</h1>
    <input type="text" id="messageInput" placeholder="输入消息...">
    <button onclick="sendMessage()">发送消息</button>
    <div id="output"></div>
    <script>
        const worker=new SharedWorker('./sharedWorker.js')
        worker.port.onmessage=function(event){
            const output=document.getElementById("output");
            output.innerHTML+=`<p>${event.data}</p>`;
        }
        function sendMessage(){
            const messageInput=document.getElementById("messageInput");
            const message=messageInput.value;
            worker.port.postMessage(message);
            messageInput.value="";
        }

        worker.port.start();
    </script>
</body>
</html>